from flask import Flask,request
from flask_sqlalchemy import SQLAlchemy
from flask_cors import CORS
# 实例化app
app = Flask(__name__)
app.config.from_pyfile("config.py")  # 使用config.py 里的 配置

# 允许跨域
CORS(app, supports_credentials=True)
# 注册数据库连接
db = SQLAlchemy(app)

import time
from datetime import timedelta

from celery import Celery

# 创建celery对象,设置任务队列使用redis
broker = 'redis://127.0.0.1:6379/0'
backend = 'redis://127.0.0.1:6379/1'
celery = Celery('test',broker=broker,backend=backend,
             #包含以下链各个任务文件，去响应的py文件中找任务，对多个任务做分类
             include=['tasks',]
             )

#beat_schedule 定义定时任务的
celery.conf.beat_schedule = {
    #名字随意命令
    'wtach_timing_send':{
        #执行tasks1下的test_celery函数
        'task':'tasks.watch_timing_send',
        'schedule':timedelta(seconds=30),
        #传递参数
        # 'args':(5,6)
    },
    # 'two_nums': {
    #     # 执行tasks1下的test_celery函数
    #     'task': 'tasks.add',
    #     'schedule': timedelta(seconds=30),
    #     # 传递参数
    #     'args':(5,6)
    # },
    # 'add-every-12-seconds':{
    #     'task':'celery_task.order_task.user_add',
    #     #每年4月11号，8点42分执行
    #     # 'schedule':crontab(minute=42,hour=8,day_of_month=11,month_of_year=4),
    #     'schedule':crontab(minute=42,hour=8,day_of_month=11,month_of_year=4),
    #     'args':(16,16)
    # }
}
